/**
 *
 */
package com.wedroid.r2d2.message;

import java.util.Date;

import com.wedroid.entity.contact.Contacter;
import com.wedroid.entity.contact.Droid;
import com.wedroid.entity.contact.GroupMember;
import com.wedroid.entity.message.Message;
import com.wedroid.entity.message.MessageType;

/**
 * @author lute
 */
public class MessageBuilder {

    private String msgId;

    private String messageType;

    private Date messageTime;

    private String content;

    private Contacter sender;

    private String senderName;

    private Contacter receiver;

    private String receiverName;

    private GroupMember groupMember;

    private String groupMemberName;

    private Droid droid;

    /**
     * @param content
     * @param messageType
     * @param messageTime
     * @param droid
     */
    public MessageBuilder(String content, MessageType messageType, Date messageTime, Droid droid) {
        this.content = content;
        this.messageType = messageType.name();
        this.messageTime = messageTime;
        this.droid = droid;
    }

    /**
     * @param msgId
     * @return
     */
    public MessageBuilder msgId(String msgId) {
        this.msgId = msgId;
        return this;
    }

    /**
     * @param sender
     * @return
     */
    public MessageBuilder sender(Contacter sender) {
        this.sender = sender;
        this.senderName = sender.getProfile().getNickName();
        return this;
    }

    /**
     * @param receiver
     * @return
     */
    public MessageBuilder receiver(Contacter receiver) {
        this.receiver = receiver;
        this.receiverName = receiver.getProfile().getNickName();
        return this;
    }

    /**
     * @param groupMember
     * @return
     */
    public MessageBuilder groupMember(GroupMember groupMember) {
        this.groupMember = groupMember;
        this.groupMemberName = groupMember.getProfile().getNickName();
        return this;
    }

    public Message build() {
        Message message = new Message();
        message.setMsgId(msgId);
        message.setMessageType(messageType);
        message.setMessageTime(messageTime);
        message.setContent(content);
        message.setSender(sender);
        message.setSenderName(senderName);
        message.setReceiver(receiver);
        message.setReceiverName(receiverName);
        message.setGroupMember(groupMember);
        message.setGroupMemberName(groupMemberName);
        message.setDroid(droid);
        return message;
    }

}
